/*
* Copyright © Shanghai Awinic Technology Co., Ltd. 2020-2020 . All rights reserved.
* Description: The header file of the PWR related driver library.
* Date： 20201126
* Awinic_Version： aw_soc_driver_v1.0.0
*/
#include "compile_option.h"
#ifdef AW_86802

#ifndef __AW8680X_PWR_H
#define __AW8680X_PWR_H

/* Include ------------------------------------------------------------------*/
#include "aw8680x_def.h"

/**
 * @brief  PWR Initialization Configuration Structure definition
**/
enum pwr_dp_flash
{
	DP_FLASH_EN = ((AW_U32)0x08),
	DP_FLASH_DIS = ((AW_U32)0x00),
};
typedef enum pwr_dp_flash PWR_DP_FLASH_TYPE_E;

/**
  * @brief power mode enumeration definition
  */
enum pwr_mode
{
	NORMAL_MODE = ((AW_U32)0x00),
	SLEEP_MODE = ((AW_U32)0x01),
	DP_SLEEP = ((AW_U32)0x02),
	POWER_DOWN = ((AW_U32)0x03),
};
typedef enum pwr_mode PWR_MODE_TYPE_E;

/**
 * @brief  PWR Initialization Configuration Structure definition
**/
struct pwr_init_struct {
	PWR_DP_FLASH_TYPE_E pwr_dp_flash;
	PWR_MODE_TYPE_E pwr_mode_e;			// Watchdog mode
	AW_U32 pwr_load_cent;				// Watchdog Timeout range
};
typedef struct pwr_init_struct PWR_INIT_TYPE_S;

/**
 * @brief  PWR Configuration Structure definition
**/
struct pwr_handle_struct {
	IRQ_PRI_E pwr_irq_pri_e;		// PWR irq priority
	PWR_INIT_TYPE_S init_s;			// PWR init struct
};
typedef struct pwr_handle_struct PWR_HANDLE_TYPE_S;

/* PWR Mode */
#define PWR_CHECK_MODE(mode) (((mode) == NORMAL_MODE) || ((mode) == SLEEP_MODE) || \
								((mode) == DP_SLEEP) || ((mode) == POWER_DOWN))

#define SLP_DELAY_NUM				(1650)
#define AW_EN						((AW_U32)0x00000001)	// Enable last bit
#define AW_DIS						(~AW_EN)				// Disable last bit
#define PWR_DELAY_TIME				(4U)
#define PWR_LOAD_CENT_OFFSET		(4U)
#define LOAD_CENT_CLEN				(0)
#define DELAY_100_US				(250U)
#define SWDT_CLR					((AW_U32)0x00000001)
#define DELAY_ONE_TIME				(1)
#define PWR_DELAY					(250)

RET_STATUS_E pwr_init(PWR_HANDLE_TYPE_S *p_pwr_lib);
void pwr_swdt_load_fun(AW_U32 pwr_load_cent);
void pwr_slp_go(void);
void pwr_clean_irq(void);
void pwr_irq(void);

#endif
#endif
